package com.snail.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snail.mapper.SysUserThirdMapper;
import com.snail.model.pojo.user.SysUserThird;
import com.snail.service.SysUserThirdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author 蔡徐坤
 * @Date 2025/8/15 15:26
 * @Description: TODO
 */
@Service
public class SysUserThirdServiceImpl extends ServiceImpl<SysUserThirdMapper, SysUserThird>implements SysUserThirdService {
    @Autowired
    private  RedisTemplate<String,Object> redisTemplate;

    @Autowired
    private SysUserThirdMapper sysUserThirdMapper;



    @Override
    public SysUserThird findByProviderAndOpenId(String provider, String openId) {
        LambdaQueryWrapper<SysUserThird> qw = new LambdaQueryWrapper<>();
        qw.eq(SysUserThird::getProvider, provider)
                .eq(SysUserThird::getProviderOpenid, openId);
        return sysUserThirdMapper.selectOne(qw);
    }

    @Override
    public void bindThirdParty(Long userId, String provider, String openId, String extraJson) {
        SysUserThird third = new SysUserThird();
        third.setUserId(userId);
        third.setProvider(provider);
        third.setProviderOpenid(openId);
        third.setExtra(extraJson);
        sysUserThirdMapper.insert(third);
    }
}
